/*
============================================================================
 Name        : dd_dtable.h
 Author      : Jian (raphyer@hotmail.com)
 Version     :
 Copyright   : GPL
 Description : dd_dtable.h - header file
============================================================================
*/

#ifndef DD_DTABLE_H
#define DD_DTABLE_H

#include "dd_define.h"

__DD_BEGIN_DECLS

/*
* A combination of array and hash_table like the table structure in LUA 
*/
typedef struct __dd_dtable dd_dtable ;
typedef void dd_dtable_value ;
typedef void dd_dtable_key ;

struct __dd_hash_node ;

struct __dd_dtable {
    dd_dtable_value**       arrayPtr ;
    DD_UINT                 arraySize ;
    DD_UINT                 arrayCount ;

    struct __dd_hash_node** hashPtr ;
    DD_UINT                 hashSize ;
    DD_UINT                 hashCount ;

    struct __dd_hash_node*  nodeTmp ;

    DD_UINT (*key_hash)(const dd_dtable_key*) ;
    DD_BOOL (*key_equal)(const dd_dtable_key*, const dd_dtable_key*) ;
};


dd_dtable* dd_dtable_create(
    DD_UINT array_init_size,    /* If the array_init_size = 0, the dd_dtable is work like a hash_table */
    DD_UINT hash_init_size,     /* If the hash_init_size = 0, the dd_dtable is work like a vector */
    DD_UINT (*key_hash)(const dd_dtable_key*),   /* Can be null, if you only use the NUMBER and STRING */
    DD_BOOL (*key_equal)(const dd_dtable_key*, const dd_dtable_key*)	/* Can be null, if you only use the NUMBER and STRING */
    ) ;

void dd_dtable_destroy(dd_dtable* dtable) ;

DD_BOOL dd_dtable_set_num(dd_dtable* dtable, DD_UINT number, dd_dtable_value* value) ;

dd_dtable_value* dd_dtable_get_num(const dd_dtable* dtable, DD_UINT number) ;

dd_dtable_value* dd_dtable_delete_num(dd_dtable* dtable, DD_UINT number) ;

void dd_dtable_set_str(dd_dtable* dtable, const char* str, dd_dtable_value* value) ;

dd_dtable_value* dd_dtable_get_str(const dd_dtable* dtable, const char* str) ;

dd_dtable_value* dd_dtable_delete_str(dd_dtable* dtable, const char* str) ;

void dd_dtable_set_key(dd_dtable* dtable, const dd_dtable_key* key, dd_dtable_value* value) ;

dd_dtable_value* dd_dtable_get_key(const dd_dtable* dtable, const dd_dtable_key* key) ;

dd_dtable_value* dd_dtable_delete_key(dd_dtable* dtable, const dd_dtable_key* key) ;


#ifdef __DD_TEST

DD_BOOL dd_dtable_test() ;

#endif

__DD_END_DECLS

#endif	/* DD_DTABLE_H */

/* End of File */
